<?php

function my_mb_truncate_text($text, $length = 30, $truncate_string = '...', $truncate_lastspace = false)
{
    mb_internal_encoding("utf-8");

    if ($text == '') {
        return '';
    }

    if (mb_strlen($text) > $length) {

        $truncate_text = mb_substr($text, 0, $length - strlen($truncate_string));

        if ($truncate_lastspace) {
            $truncate_text = mb_preg_replace('/\s+?(\S+)?$/', '', $truncate_text);
        }

        return $truncate_text.$truncate_string;

    } else {
        return $text;
    }
}

